home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / JOHNLOVE / C_SOURCE / HELP.C < prev    next >
Text File  |  1992-01-17  |  5KB  |  221 lines

  1. /*********************************************************
  2.  "help.c"
  3.  
  4.  by John A. Love, III [Washington Apple Pi Users' Group]
  5.  
  6.  using Symantec's "THINK C", v 5.00
  7.  *********************************************************/
  8.  
  9.  
  10. #include <GestaltEqu.h>
  11. #include <OSChecks.h>
  12. #include <Traps.h>
  13.  
  14. #include "CmyGlobals.h"
  15. #include "help.h"
  16.  
  17.  
  18. // Local prototype(s):
  19.  
  20. OSErr    ShowMyNewBalloon (Rect        *altRect,
  21.                           Ptr        tipProc,
  22.                           short        strID,
  23.                           short        strIndex,
  24.                           short        theProc,
  25.                           short        variant,
  26.                           short        method);
  27.  
  28.  
  29.         Point                mouse;
  30.         short                notMine = -1;
  31.  
  32.  
  33.  
  34.         
  35. Boolean HelpManagerActive (void)    {
  36.  /* Do we have a machine on which the Help Manager exists ??? */
  37.  
  38.         short        _Gestalt = 0xA1AD;
  39.         long        myFeature;
  40.         Boolean        result;
  41.  
  42.  
  43.     result = false;
  44.     ;
  45.     if (TrapAvailable(_Gestalt))    {
  46.         if (Gestalt(gestaltHelpMgrAttr, &myFeature) == noErr)    {
  47.             if (BitTst(&myFeature, 31 - gestaltHelpMgrPresent))    result = true;
  48.         }
  49.     }
  50.  
  51.     return(result);
  52.     
  53. }    /* HelpManagerActive */
  54.  
  55.  
  56.  
  57. Boolean BalloonsOn (void)    {
  58. /* Has the user selected "Show Balloons" ??? */
  59.  
  60.     return(HelpManagerActive() && HMGetBalloons());
  61.  
  62. }    /* BalloonsOn */
  63.  
  64.  
  65.  
  66. Boolean BalloonShowing (void)    {
  67. /* Is a Balloon currently showing ??? */
  68.  
  69.     return(HelpManagerActive() && HMIsBalloon());
  70.  
  71. }    /* BalloonShowing */
  72.  
  73.  
  74.  
  75. void HideBalloons (Boolean balloonsUp)    {
  76.  
  77.         OSErr    soWhat;
  78.  
  79.  
  80.     if (balloonsUp)    {
  81.         /* Get the daggum monster out of the way !! */
  82.         /* Used "hmSaveBitsNoWindow option" so bits */
  83.         /* are restored withOUT an update Event.    */
  84.         if (BalloonShowing())    soWhat = HMRemoveBalloon();
  85.                 
  86.         /* Okay, I've restored the bits.  However, now   */
  87.         /* I've got to temporarily disable Balloon Help  */
  88.         /* until I leave with a Mouse Up Event or finish */
  89.         /* with whatever:                                */
  90.         soWhat = HMSetBalloons(false);
  91.         ;
  92.         gLastBalloon = -1;
  93.     }    /* "Show Balloons" active */
  94.  
  95. }    /* HideBalloons */
  96.  
  97.  
  98. void ShowBalloons (Boolean balloonsUp)    {
  99. /* NOW !!! I can safely re-enable Balloon Help: */
  100.  
  101.         OSErr    soWhat;
  102.  
  103.  
  104.     if (balloonsUp)    soWhat = HMSetBalloons(true);
  105.  
  106. }    /* ShowBalloons */
  107.  
  108.  
  109.  
  110. void ResetBalloons (Boolean balloonsUp)    {
  111.  
  112.     if (balloonsUp)    ShowBalloons(true);
  113.     else            HideBalloons(HelpManagerActive());
  114.  
  115. }    /* ResetBalloons */
  116.  
  117.  
  118.  
  119. OSErr ShowMyNewBalloon (Rect    *altRect,
  120.                         Ptr        tipProc,
  121.                         short    strID,
  122.                         short    strIndex,
  123.                         short    theProc,
  124.                         short    variant,
  125.                         short    method)        {
  126.  
  127.         HMMessageRecord        helpMsg;
  128.         Point                tip;
  129.         Rect                cyAltRect;
  130.  
  131.  
  132.  /* See comment besides "nil" passed to HMShowBalloon below:
  133.  
  134.     // ... so we don't change the input Rect:
  135.     cyAltRect = *altRect;
  136.     LocalGlobal(&cyAltRect);
  137.  
  138.     // If we centered the tip and the window is partially
  139.     // hidden by, say, a Floating Window, the tip may end
  140.     // up pointing to the Floating Window:
  141.  
  142.  /*
  143.     // Center the tip:
  144.     SetPt(&tip,
  145.           (cyAltRect.right  + cyAltRect.left)/2,
  146.           (cyAltRect.bottom + cyAltRect.top )/2);
  147.  */
  148.      GetMouse(&tip);
  149.      LocalToGlobal(&tip);
  150.     
  151.     // Fill in HMMessageRecord:
  152.     helpMsg.hmmHelpType             = khmmStringRes;
  153.     helpMsg.u.hmmStringRes.hmmResID    = strID;
  154.     helpMsg.u.hmmStringRes.hmmIndex    = strIndex;
  155.     ;
  156.     return ( HMShowBalloon(&helpMsg, tip,
  157.                            nil,            /* If I pass &cyAltRect, the Help Manager
  158.                                            ** will attempt to re-calculate the tip.
  159.                                            ** This is exactly what I do NOT want
  160.                                            ** because of the possibility that a
  161.                                            ** Floating Window may be covering part
  162.                                            ** of a DLOG item in which case the
  163.                                            ** re-calculated tip may end up pointing
  164.                                            ** to the Floating Window.                 */
  165.                            tipProc, theProc, variant, method) );
  166.  
  167. }    /* ShowMyNewBalloon */
  168.  
  169.  
  170.  
  171. void FindAndShowDynamicBalloons (Boolean balloonsUp)    {
  172.  
  173.         short                stdWDEF = 0, defVar = 0;
  174.         short                part, activeOtherWindow = -1000;
  175.         EventRecord            macEvent;
  176.         GrafPtr                savePort;
  177.         WindowPtr            inWindow;
  178.  
  179.  
  180.      if ( !balloonsUp ||
  181.           EventAvail(updateMask, &macEvent) /* "Switch-A_Roo" problem */ )        {
  182.         gLastBalloon = notMine;
  183.         return;
  184.     }
  185.  
  186.     GetMouse(&mouse);
  187.     LocalToGlobal(&mouse);
  188.     part = FindWindow(mouse, &inWindow);
  189.     
  190.     if (part != inContent)        return;
  191.  
  192.     else    {    /* mouse is in a window somewhere */
  193.                 
  194.         GetPort(&savePort);
  195.         SetPort(inWindow);
  196.         
  197.         GlobalToLocal(&mouse);
  198.  
  199.         if ( inWindow == FrontWindow() )    {
  200.             /* mouse in front, or active window */    
  201.  
  202.  
  203.         }    /* Cursor in SOME active window */
  204.         
  205.         else    /* Cursor in an inactive window */    {
  206.         
  207.             /* The 'hovr' resource handles this case. */
  208.             
  209.         }    /* Cursor in SOME inactive window */
  210.         
  211.         SetPort(savePort);
  212.  
  213.     }    /* Mouse is somewhere in a window */
  214.                     
  215. }    /* FindAndShowDynamicBalloons */
  216.  
  217.  
  218.  
  219.  
  220. /*    { end file "help.c" }  */
  221.